Maverick
Maverick

Reputation: 587

Spreadsheet::ParseExcel module in perl

I always gets confused when I deal with Classes and Objects. As I am trying to understand the Spreadsheet::ParseExcel module, I am having some doubts for its classes and object :

My doubt is:

With $parser= Spreadsheet::ParseExcel->new();, we are creating an object for Spreadsheet::ParseExcel and after this we shall create the object for Spreadsheet::ParseExcel::Workbook.
Why can not we create the object directly for Spreadsheet::ParseExcel::Workbook and start parsing ?

Thanks

Upvotes: 0

Views: 552

Answers (2)

jmcnamara
jmcnamara

Reputation: 41564

Why can not we create the object directly for Spreadsheet::ParseExcel::Workbook and start parsing

That is a reasonable question and in older versions of Spreadsheet::ParseExcel there was a Spreadsheet::ParseExcel::Workbook->Parse() method that did just that. (*)

Users tend to see an Excel file only as a workbook. However the file format also contains data such as metadata (author, creation date, etc.) and vba macros that are separate from the workbook data.

As such the logical division of the parser from the workbook probably occurred due to the physical division of the data in the file.

Or it may have been to allow reporting of file parsing errors rather than just returning an undefined workbook object.

Either way, other people may have chosen to model the interface differently but that is what the original author chose. It is not completely intuitive but it works.

(*) This method is now deprecated since it doesn't allow error checking on the file.

Upvotes: 4

s0me0ne
s0me0ne

Reputation: 516

Think about Spreadsheet::ParseExcel and Spreadsheet::ParseExcel::Workbook like they are just of different types, like integer and string, which are both scalar, but you cannot, say, multiply them, although they can interact in some cases. E.g. length() applied to string gives you integer length of string. The same way, Spreadsheet::ParseExcel::parse() gives you Spreadsheet::ParseExcel::Workbook. They are bound by common namespace but they are completely different, Spreadsheet::ParseExcel is a parser and Spreadsheet::ParseExcel::Workbook is a workbook.

Upvotes: 2

Related Questions