home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Mac / AppleEvents.pm next >
Text File  |  1998-04-05  |  19KB  |  911 lines

  1. =head1 NAME
  2.  
  3. Mac::AppleEvents - Macintosh Toolbox Interface to the Apple Event Manager
  4.  
  5. =head1 SYNOPSIS
  6.  
  7.     use Mac::AppleEvents;
  8.  
  9.  
  10. =head1 DESCRIPTION
  11.  
  12. Access to Inside Macintosh is essential for proper use of these functions.
  13. Explanations of terms, processes and procedures are provided there.
  14. Any attempt to use these functions without guidance can cause severe errors in 
  15. your machine, including corruption of data. B<You have been warned.>
  16.  
  17. =cut
  18.  
  19. use strict;
  20.  
  21. package Mac::AppleEvents;
  22.  
  23. BEGIN {
  24.     use Exporter   ();
  25.     use DynaLoader ();
  26.     
  27.     use vars qw(@ISA @EXPORT %AppleEvent %SysAppleEvent);
  28.     
  29.     @ISA = qw(Exporter DynaLoader);
  30.     @EXPORT = qw(
  31.         AECreateDesc
  32.         AECoerce
  33.         AECoerceDesc
  34.         AEDisposeDesc
  35.         AEDuplicateDesc
  36.         AECreateList
  37.         AECountItems
  38.         AEPut
  39.         AEPutDesc
  40.         AEGetNthDesc
  41.         AEDeleteItem
  42.         AEPutParam
  43.         AEPutParamDesc
  44.         AEGetParamDesc
  45.         AEDeleteParam
  46.         AEGetAttributeDesc
  47.         AEPutAttribute
  48.         AEPutAttributeDesc
  49.         AECreateAppleEvent
  50.         AESend
  51.         AEResetTimer
  52.         AESuspendTheCurrentEvent
  53.         AEResumeTheCurrentEvent
  54.         AEGetTheCurrentEvent
  55.         AESetTheCurrentEvent
  56.         AEGetInteractionAllowed
  57.         AESetInteractionAllowed
  58.         AEInstallEventHandler
  59.         AERemoveEventHandler
  60.         AEGetEventHandler
  61.         AEManagerInfo
  62.         AEBuild
  63.         AEBuildParameters
  64.         AEBuildAppleEvent
  65.         AEPrint
  66.         AEDescToSubDesc
  67.         AEGetSubDescType
  68.         AEGetSubDescBasicType
  69.         AESubDescIsListOrRecord
  70.         AEGetSubDescData
  71.         AESubDescToDesc
  72.         AECountSubDescItems
  73.         AEGetNthSubDesc
  74.         AEGetKeySubDesc
  75.         
  76.         %AppleEvent
  77.         %SysAppleEvent
  78.         typeBoolean
  79.         typeChar
  80.         typeInteger
  81.         typeFloat
  82.         typeLongInteger
  83.         typeShortInteger
  84.         typeLongFloat
  85.         typeShortFloat
  86.         typeExtended
  87.         typeComp
  88.         typeMagnitude
  89.         typeAEList
  90.         typeAERecord
  91.         typeAppleEvent
  92.         typeTrue
  93.         typeFalse
  94.         typeAlias
  95.         typeEnumerated
  96.         typeType
  97.         typeAppParameters
  98.         typeProperty
  99.         typeFSS
  100.         typeKeyword
  101.         typeSectionH
  102.         typeWildCard
  103.         typeApplSignature
  104.         typeQDRectangle
  105.         typeFixed
  106.         typeSessionID
  107.         typeTargetID
  108.         typeProcessSerialNumber
  109.         typeNull
  110.         keyDirectObject
  111.         keyErrorNumber
  112.         keyErrorString
  113.         keyProcessSerialNumber
  114.         keyTransactionIDAttr
  115.         keyReturnIDAttr
  116.         keyEventClassAttr
  117.         keyEventIDAttr
  118.         keyAddressAttr
  119.         keyOptionalKeywordAttr
  120.         keyTimeoutAttr
  121.         keyInteractLevelAttr
  122.         keyEventSourceAttr
  123.         keyMissedKeywordAttr
  124.         keyOriginalAddressAttr
  125.         keyPreDispatch
  126.         keySelectProc
  127.         keyAERecorderCount
  128.         keyAEVersion
  129.         kCoreEventClass
  130.         kAEOpenApplication
  131.         kAEOpenDocuments
  132.         kAEPrintDocuments
  133.         kAEQuitApplication
  134.         kAEAnswer
  135.         kAEApplicationDied
  136.         kAENoReply
  137.         kAEQueueReply
  138.         kAEWaitReply
  139.         kAENeverInteract
  140.         kAECanInteract
  141.         kAEAlwaysInteract
  142.         kAECanSwitchLayer
  143.         kAEDontReconnect
  144.         kAEWantReceipt
  145.         kAEDontRecord
  146.         kAEDontExecute
  147.         kAENormalPriority
  148.         kAEHighPriority
  149.         kAEStartRecording
  150.         kAEStopRecording
  151.         kAENotifyStartRecording
  152.         kAENotifyStopRecording
  153.         kAENotifyRecording
  154.         kAutoGenerateReturnID
  155.         kAnyTransactionID
  156.         kAEDefaultTimeout
  157.         kNoTimeOut
  158.         kAENoDispatch
  159.         kAEUseStandardDispatch
  160.         kAEDoNotIgnoreHandler
  161.         kAEIgnoreAppPhacHandler
  162.         kAEIgnoreAppEventHandler
  163.         kAEIgnoreSysPhacHandler
  164.         kAEIgnoreSysEventHandler
  165.         kAEIngoreBuiltInEventHandler
  166.         kAEDontDisposeOnResume
  167.         kAEInteractWithSelf
  168.         kAEInteractWithLocal
  169.         kAEInteractWithAll
  170.         kAEUnknownSource
  171.         kAEDirectCall
  172.         kAESameProcess
  173.         kAELocalProcess
  174.         kAERemoteProcess
  175.         kAEDataArray
  176.         kAEPackedArray
  177.         kAEHandleArray
  178.         kAEDescArray
  179.         kAEKeyDescArray
  180.     );
  181. }
  182.  
  183. bootstrap Mac::AppleEvents;
  184.  
  185. package Mac::AppleEvents::EventHandler;
  186.  
  187. BEGIN {
  188.     import Mac::AppleEvents;
  189.  
  190.     use Carp;
  191. }
  192.  
  193. sub TIEHASH
  194. {
  195.     my ($package,$sys) = @_;
  196.     my ($me) = bless {SYS => $sys};
  197.     
  198.     return $me;
  199. }
  200.  
  201. sub ParseKey 
  202. {
  203.     my($key) = @_;
  204.     
  205.     return (substr($key, 0, 4), substr($key, -4));
  206. }
  207.  
  208. sub FETCH 
  209. {  
  210.     my($sys,$key)  = @_;
  211.     my(@keys) = ParseKey $key;
  212.  
  213.     my ($handler, $refcon) = AEGetEventHandler(@keys, $sys->{SYS});
  214.     
  215.     return wantarray ? ($handler,$refcon) : $handler;
  216. }
  217.  
  218.  
  219. sub STORE 
  220. {
  221.     my($sys,$key,$handler,$refcon) = @_;
  222.     my(@keys) = ParseKey $key;
  223.     
  224.     $refcon = $key unless defined $refcon;
  225.     
  226.     AEInstallEventHandler(@keys, $handler, $refcon, $sys->{SYS}) || die;
  227. }
  228.  
  229. sub DELETE 
  230. {   
  231.     my($sys,$key)  = @_;
  232.     my(@keys) = ParseKey $key;
  233.     
  234.     AERemoveEventHandler(@keys, $sys->{SYS});
  235. }
  236.  
  237. sub DESTROY 
  238. {
  239.     my($sys)  = @_;
  240.     
  241.     undef %{$sys};
  242. }
  243.  
  244. sub FIRSTKEY { croak "Mac::AppleEvents::EventHandler::FIRSTKEY is not implemented" }
  245. sub NEXTKEY { croak "Mac::AppleEvents::EventHandler::NEXTKEY is not implemented" }
  246. sub EXISTS { croak "Mac::AppleEvents::EventHandler::EXISTS is not implemented" }
  247. sub CLEAR { croak "Mac::AppleEvents::EventHandler::CLEAR is not implemented" }
  248.  
  249. package Mac::AppleEvents;
  250.  
  251. =head2 Constants: AppleEvent Descriptor Types
  252.  
  253. =over 4
  254.  
  255. =item  typeBoolean 
  256.  
  257. A boolean.
  258.  
  259. =item  typeTrue 
  260.  
  261. A boolean True value.
  262.  
  263. =item  typeFalse 
  264.  
  265. A boolean False value.
  266.  
  267. =item  typeChar 
  268.  
  269. A string.
  270.  
  271. =item  typeShortInteger 
  272.  
  273. A 16 bit integer.
  274.  
  275. =item  typeInteger 
  276.  
  277. =item  typeLongInteger 
  278.  
  279. A 32 bit integer.
  280.  
  281. =item  typeMagnitude 
  282.  
  283. An unsigned 32 bit integer.
  284.  
  285. =item  typeShortFloat 
  286.  
  287. A single precision floating point number.
  288.  
  289. =item  typeFloat 
  290.  
  291. =item  typeLongFloat 
  292.  
  293. A double precision floating point number.
  294.  
  295. =item  typeExtended 
  296.  
  297. An extended double precision floating point number.
  298.  
  299. =item  typeComp 
  300.  
  301. A 64 bit number.
  302.  
  303. =item  typeAEList 
  304.  
  305. An AppleEvent list.
  306.  
  307. =item  typeAERecord 
  308.  
  309. An AppleEvent record.
  310.  
  311. =item  typeAppleEvent 
  312.  
  313. An AppleEvent.
  314.  
  315. =item  typeFSS 
  316.  
  317. A file specification record.
  318.  
  319. =item  typeAlias 
  320.  
  321. A file alias record.
  322.  
  323. =item  typeEnumerated 
  324.  
  325. An enumeration literal (4 byte character).
  326.  
  327. =item  typeType 
  328.  
  329. An AppleEvent type (4 byte character).
  330.  
  331. =item  typeAppParameters 
  332.  
  333. An application launch parameter record.
  334.  
  335. =item  typeProperty 
  336.  
  337. A property keyword (4 byte character).
  338.  
  339. =item  typeKeyword 
  340.  
  341. A keyword (4 byte character).
  342.  
  343. =item  typeSectionH 
  344.  
  345. An Edition Manager section handle.
  346.  
  347. =item  typeWildCard 
  348.  
  349. An arbitrary value.
  350.  
  351. =item  typeApplSignature 
  352.  
  353. An application signature (4 byte character).
  354.  
  355. =item  typeQDRectangle 
  356.  
  357. A QuickDraw rectangle.
  358.  
  359. =item  typeFixed 
  360.  
  361. A fixed point value.
  362.  
  363. =item  typeSessionID 
  364.  
  365. A PPC Toolbox session ID.
  366.  
  367. =item  typeTargetID 
  368.  
  369. A target ID record.
  370.  
  371. =item  typeProcessSerialNumber 
  372.  
  373. A process serial number.
  374.  
  375. =item  typeNull 
  376.  
  377. No data.
  378.  
  379. =back
  380.  
  381. =cut
  382. sub typeBoolean                    {     "bool"; }
  383. sub typeChar                       {     "TEXT"; }
  384. sub typeSMInt                      {     "shor"; }
  385. sub typeInteger                    {     "long"; }
  386. sub typeSMFloat                    {     "sing"; }
  387. sub typeFloat                      {     "doub"; }
  388. sub typeLongInteger                {     "long"; }
  389. sub typeShortInteger               {     "shor"; }
  390. sub typeLongFloat                  {     "doub"; }
  391. sub typeShortFloat                 {     "sing"; }
  392. sub typeExtended                   {     "exte"; }
  393. sub typeComp                       {     "comp"; }
  394. sub typeMagnitude                  {     "magn"; }
  395. sub typeAEList                     {     "list"; }
  396. sub typeAERecord                   {     "reco"; }
  397. sub typeAppleEvent                 {     "aevt"; }
  398. sub typeTrue                       {     "true"; }
  399. sub typeFalse                      {     "fals"; }
  400. sub typeAlias                      {     "alis"; }
  401. sub typeEnumerated                 {     "enum"; }
  402. sub typeType                       {     "type"; }
  403. sub typeAppParameters              {     "appa"; }
  404. sub typeProperty                   {     "prop"; }
  405. sub typeFSS                        {     "fss "; }
  406. sub typeKeyword                    {     "keyw"; }
  407. sub typeSectionH                   {     "sect"; }
  408. sub typeWildCard                   {     "****"; }
  409. sub typeApplSignature              {     "sign"; }
  410. sub typeQDRectangle                {     "qdrt"; }
  411. sub typeFixed                      {     "fixd"; }
  412. sub typeSessionID                  {     "ssid"; }
  413. sub typeTargetID                   {     "targ"; }
  414. sub typeProcessSerialNumber        {     "psn "; }
  415. sub typeNull                       {     "null"; }
  416.  
  417. =head2 Constants: Parameter and Attribute Keywords
  418.  
  419. =over 4
  420.  
  421. =item  keyDirectObject 
  422.  
  423. The direct object parameter.
  424.  
  425. =item  keyErrorNumber 
  426.  
  427. Error number.
  428.  
  429. =item  keyErrorString 
  430.  
  431. Error string.
  432.  
  433. =item  keyProcessSerialNumber 
  434.  
  435. Process serial number.
  436.  
  437. =item  keyTransactionIDAttr 
  438.  
  439. Transaction ID.
  440.  
  441. =item  keyReturnIDAttr 
  442.  
  443. Return ID.
  444.  
  445. =item  keyEventClassAttr 
  446.  
  447. Event class.
  448.  
  449. =item  keyEventIDAttr 
  450.  
  451. Event ID.
  452.  
  453. =item  keyAddressAttr 
  454.  
  455. Destination address.
  456.  
  457. =item  keyOptionalKeywordAttr 
  458.  
  459. List of optional keywords.
  460.  
  461. =item  keyTimeoutAttr 
  462.  
  463. Timeout limit.
  464.  
  465. =item  keyInteractLevelAttr 
  466.  
  467. Interaction level.
  468.  
  469. =item  keyEventSourceAttr 
  470.  
  471. Event source address.
  472.  
  473. =item  keyMissedKeywordAttr 
  474.  
  475. List of mandatory keywords not used.
  476.  
  477. =item  keyOriginalAddressAttr 
  478.  
  479. Original source address.
  480.  
  481. =item  keyPreDispatch 
  482.  
  483. Install handler before dispatching.
  484.  
  485. =item  keySelectProc 
  486.  
  487. Enable/Disable OSL.
  488.  
  489. =item  keyAERecorderCount 
  490.  
  491. Number of processes recording AppleEvents.
  492.  
  493. =item  keyAEVersion 
  494.  
  495. AppleEvent Manager version.
  496.  
  497. =back
  498.  
  499. =cut
  500. sub keyDirectObject                {     "----"; }
  501. sub keyErrorNumber                 {     "errn"; }
  502. sub keyErrorString                 {     "errs"; }
  503. sub keyProcessSerialNumber         {     "psn "; }
  504. sub keyTransactionIDAttr           {     "tran"; }
  505. sub keyReturnIDAttr                {     "rtid"; }
  506. sub keyEventClassAttr              {     "evcl"; }
  507. sub keyEventIDAttr                 {     "evid"; }
  508. sub keyAddressAttr                 {     "addr"; }
  509. sub keyOptionalKeywordAttr         {     "optk"; }
  510. sub keyTimeoutAttr                 {     "timo"; }
  511. sub keyInteractLevelAttr           {     "inte"; }
  512. sub keyEventSourceAttr             {     "esrc"; }
  513. sub keyMissedKeywordAttr           {     "miss"; }
  514. sub keyOriginalAddressAttr         {     "from"; }
  515. sub keyPreDispatch                 {     "phac"; }
  516. sub keySelectProc                  {     "selh"; }
  517. sub keyAERecorderCount             {     "recr"; }
  518. sub keyAEVersion                   {     "vers"; }
  519.  
  520. =head2 Constants: Core AppleEvent Suite
  521.  
  522. =over 4
  523.  
  524. =item  kCoreEventClass 
  525.  
  526. Core Suite Event class.
  527.  
  528. =item  kAEOpenApplication 
  529.  
  530. Open application without documents.
  531.  
  532. =item  kAEOpenDocuments 
  533.  
  534. Open documents.
  535.  
  536. =item  kAEPrintDocuments 
  537.  
  538. Print documents.
  539.  
  540. =item  kAEQuitApplication 
  541.  
  542. Quit application.
  543.  
  544. =item  kAEAnswer 
  545.  
  546. AppleEvent answer event.
  547.  
  548. =item  kAEApplicationDied 
  549.  
  550. Launched application has ended.
  551.  
  552. =back
  553.  
  554. =cut
  555. sub kCoreEventClass                {     "aevt"; }
  556. sub kAEOpenApplication             {     "oapp"; }
  557. sub kAEOpenDocuments               {     "odoc"; }
  558. sub kAEPrintDocuments              {     "pdoc"; }
  559. sub kAEQuitApplication             {     "quit"; }
  560. sub kAEAnswer                      {     "ansr"; }
  561. sub kAEApplicationDied             {     "obit"; }
  562.  
  563. =head2 Constants: Miscellaneous
  564.  
  565. =over 4
  566.  
  567. =item  kAENoReply 
  568.  
  569. =item  kAEQueueReply 
  570.  
  571. =item  kAEWaitReply 
  572.  
  573. =item  kAENeverInteract 
  574.  
  575. =item  kAECanInteract 
  576.  
  577. =item  kAEAlwaysInteract 
  578.  
  579. =item  kAECanSwitchLayer 
  580.  
  581. =item  kAEDontReconnect 
  582.  
  583. =item  kAEWantReceipt 
  584.  
  585. =item  kAEDontRecord 
  586.  
  587. =item  kAEDontExecute 
  588.  
  589. =item  kAEInteractWithSelf 
  590.  
  591. =item  kAEInteractWithLocal 
  592.  
  593. =item  kAEInteractWithAll 
  594.  
  595. AppleEvent sendMode flags.
  596.  
  597. =cut
  598. sub kAENoReply                     { 0x00000001; }
  599. sub kAEQueueReply                  { 0x00000002; }
  600. sub kAEWaitReply                   { 0x00000003; }
  601. sub kAENeverInteract               { 0x00000010; }
  602. sub kAECanInteract                 { 0x00000020; }
  603. sub kAEAlwaysInteract              { 0x00000030; }
  604. sub kAECanSwitchLayer              { 0x00000040; }
  605. sub kAEDontReconnect               { 0x00000080; }
  606. sub kAEWantReceipt                 { 0x00000200; }
  607. sub kAEDontRecord                  { 0x00001000; }
  608. sub kAEDontExecute                 { 0x00002000; }
  609. sub kAEInteractWithSelf            {          0; }
  610. sub kAEInteractWithLocal           {          1; }
  611. sub kAEInteractWithAll             {          2; }
  612.  
  613. =item  kAENormalPriority 
  614.  
  615. =item  kAEHighPriority 
  616.  
  617. AppleEvent priority values.
  618.  
  619. =cut
  620. sub kAENormalPriority              { 0x00000000; }
  621. sub kAEHighPriority                { 0x00000001; }
  622.  
  623. =item  kAEStartRecording 
  624.  
  625. =item  kAEStopRecording 
  626.  
  627. =item  kAENotifyStartRecording 
  628.  
  629. =item  kAENotifyStopRecording 
  630.  
  631. =item  kAENotifyRecording 
  632.  
  633. Recording events.
  634.  
  635. =cut
  636. sub kAEStartRecording              {     "reca"; }
  637. sub kAEStopRecording               {     "recc"; }
  638. sub kAENotifyStartRecording        {     "rec1"; }
  639. sub kAENotifyStopRecording         {     "rec0"; }
  640. sub kAENotifyRecording             {     "recr"; }
  641.  
  642. =item  kAutoGenerateReturnID 
  643.  
  644. =item  kAnyTransactionID 
  645.  
  646. =item  kAEDefaultTimeout 
  647.  
  648. =item  kNoTimeOut 
  649.  
  650. Special values for return ID, transaction ID, and timeout.
  651.  
  652. =cut
  653. sub kAutoGenerateReturnID          {         -1; }
  654. sub kAnyTransactionID              {          0; }
  655. sub kAEDefaultTimeout              {         -1; }
  656. sub kNoTimeOut                     {         -2; }
  657.  
  658. =item  kAENoDispatch 
  659.  
  660. =item  kAEUseStandardDispatch 
  661.  
  662. =item  kAEDoNotIgnoreHandler 
  663.  
  664. =item  kAEIgnoreAppPhacHandler 
  665.  
  666. =item  kAEIgnoreAppEventHandler 
  667.  
  668. =item  kAEIgnoreSysPhacHandler 
  669.  
  670. =item  kAEIgnoreSysEventHandler 
  671.  
  672. =item  kAEIngoreBuiltInEventHandler 
  673.  
  674. =item  kAEDontDisposeOnResume 
  675.  
  676. Options for C<AEResumeTheCurrentEvent()>.
  677.  
  678. =cut
  679. sub kAENoDispatch                  {          0; }
  680. sub kAEUseStandardDispatch         { 0xFFFFFFFF; }
  681. sub kAEDoNotIgnoreHandler          { 0x00000000; }
  682. sub kAEIgnoreAppPhacHandler        { 0x00000001; }
  683. sub kAEIgnoreAppEventHandler       { 0x00000002; }
  684. sub kAEIgnoreSysPhacHandler        { 0x00000004; }
  685. sub kAEIgnoreSysEventHandler       { 0x00000008; }
  686. sub kAEIngoreBuiltInEventHandler   { 0x00000010; }
  687. sub kAEDontDisposeOnResume         { 0x80000000; }
  688.  
  689. sub kAEUnknownSource               {          0; }
  690. sub kAEDirectCall                  {          1; }
  691. sub kAESameProcess                 {          2; }
  692. sub kAELocalProcess                {          3; }
  693. sub kAERemoteProcess               {          4; }
  694. sub kAEDataArray                   {          0; }
  695. sub kAEPackedArray                 {          1; }
  696. sub kAEHandleArray                 {          2; }
  697. sub kAEDescArray                   {          3; }
  698. sub kAEKeyDescArray                {          4; }
  699.  
  700. =back
  701.  
  702. =head2 Variables
  703.  
  704. =over 4
  705.  
  706. =item %AppleEvent
  707.  
  708. An array of application-wide event handlers.
  709.  
  710.    $AppleEvent{"aevt", "odoc"} = \&OpenDocument;
  711.  
  712. =item %SysAppleEvent
  713.  
  714. An arrary of system-wide event handlers.
  715.  
  716. =back
  717.  
  718. =cut
  719. tie %AppleEvent,    q(Mac::AppleEvents::EventHandler), 0;
  720. tie %SysAppleEvent, q(Mac::AppleEvents::EventHandler), 1;
  721.  
  722. my(%constant) = (
  723.     "true" => 1,
  724.     "fals" => 0,
  725.     "null" => "",
  726. );
  727.  
  728. package AEDesc;
  729.  
  730. =head2 AEDesc
  731.  
  732. AEDesc is a Perl package that encapsulates an AppleEvent Descriptor.
  733. It uses the OO methods of Perl5 to make building and parsing data structures
  734. easier.
  735.  
  736. =item new TYPE, HANDLE
  737.  
  738. =item new TYPE, DATA
  739.  
  740. =item new TYPE
  741.  
  742. =item new
  743.  
  744. Create a new AppleEvent descriptor.
  745. Sets the type and data to TYPE (default is 'null'), and HANDLE or DATA 
  746. (default is empty).
  747.  
  748.     $desc = new AEDesc("aevt", $event);
  749.  
  750. =item type TYPE
  751.  
  752. =item type
  753.  
  754. Return the type from the AEDesc structure.  
  755. If TYPE is present, make it the new type.
  756.  
  757. =item data HANDLE
  758.  
  759. =item data
  760.  
  761. Return the data from the AEDesc structure. If HANDLE is present, make
  762. it the new data.
  763.  
  764. =item get
  765.  
  766. Return the data of the AEDesc structure in a smartly unpacked way.
  767.  
  768. =back
  769.  
  770. =cut
  771.  
  772. BEGIN {
  773.     use Mac::Memory ();
  774.     use Mac::Types;
  775. }
  776.  
  777. sub new {
  778.     my($package, $type, $data) = @_;
  779.     
  780.     if (defined($data) && ref($data) ne "Handle") {
  781.         _new($package, $type, new Handle($data));
  782.     } else {
  783.         _new(@_);
  784.     }
  785. }
  786.  
  787. sub get () {
  788.     my($desc) = @_;
  789.     my($type) = $desc->type;
  790.     
  791.     if (exists($constant{$type})) {
  792.         return $constant{$type};
  793.     } elsif (exists($MacUnpack{$type})) {
  794.         return MacUnpack($type, $desc->data->get);
  795.     } else {
  796.         return &Mac::AppleEvents::AEPrint($desc);
  797.     }
  798. }
  799.  
  800. package AESubDesc;
  801.  
  802. BEGIN {
  803.     use Mac::Memory ();
  804.     use Mac::Types;
  805.     import Mac::AppleEvents;
  806. }
  807.  
  808. sub get () {
  809.     my($desc) = @_;
  810.     my($type) = AEGetSubDescType($desc);
  811.     
  812.     if (exists($constant{$type})) {
  813.         return $constant{$type};
  814.     } elsif (exists($MacUnpack{$type})) {
  815.         return MacUnpack($type, AEGetSubDescData($desc));
  816.     } else {
  817.         my($aedesc,$res) = AESubDescToDesc($desc);
  818.         $res = AEPrint($aedesc);
  819.         AEDisposeDesc($aedesc);
  820.         
  821.         return $res;
  822.     }
  823. }
  824.  
  825. package AEKeyDesc;
  826.  
  827. =head2 AEKeyDesc
  828.  
  829. AEKeyDesc is a Perl package that encapsulates an AppleEvent keyword.
  830. It uses the OO methods of Perl5 to make building and parsing data structures
  831. easier.
  832.  
  833. =item new KEY, TYPE, HANDLE
  834.  
  835. =item new KEY, TYPE, DATA
  836.  
  837. =item new KEY, TYPE
  838.  
  839. =item new KEY
  840.  
  841. =item new
  842.  
  843. Creates a new AppleEvent keyword descriptor.
  844. Sets the keyword, type and data to KEY (default is zero),
  845. TYPE (default is 'null'), and HANDLE or DATA (default is empty).
  846.  
  847. =item key KEY
  848.  
  849. =item key
  850.  
  851. Return the keyword of the AEKeyDesc structure.
  852. If KEY is present, make it the new keyword.
  853.  
  854. =item type TYPE
  855.  
  856. =item type
  857.  
  858. Return the type from the AEKeyDesc structure.  If TYPE is present, make it the new type.
  859.  
  860. =item data HANDLE
  861.  
  862. =item data
  863.  
  864. Return the data from the AEKeyDesc structure. If HANDLE is present, make
  865. it the new data.
  866.  
  867. =item get
  868.  
  869. Return the contents in a smartly unpacked way.
  870.  
  871. =back
  872.  
  873. =cut
  874.  
  875. sub new {
  876.     my($package, $key, $type, $data) = @_;
  877.     
  878.     if (defined($data) && ref($data) ne "Handle") {
  879.         _new($package, $key, $type, new Handle($data));
  880.     } else {
  881.         _new(@_);
  882.     }
  883. }
  884.  
  885. package AEStream;
  886.  
  887. sub new {
  888.     my($package) = shift @_;
  889.     
  890.     if (!scalar(@_)) {
  891.         Open();
  892.     } elsif (scalar(@_) == 1) {
  893.         OpenEvent(@_);
  894.     } else {
  895.         CreateEvent(@_);
  896.     }
  897. }
  898.  
  899. =include AppleEvents.xs
  900.  
  901. =head1 AUTHOR
  902.  
  903. Matthias Ulrich Neeracher neeri@iis.ee.ethz.ch "Programs"
  904.  
  905. Bob Dalgleish bob.dalgleish@sasknet.sk.ca "Documentation"
  906.  
  907. =cut
  908. 1;
  909.  
  910. __END__
  911.